﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNASpelProjekt
{
    /// <summary>
    /// Base class for all bullets fired by the player.
    /// </summary>
    public abstract class PlayerBulletActor : BulletActor
    {
        #region Member Variables
        public static int Count { get; set; }           //antalet aktiva objekt av klassen

        #endregion

        #region public methods

        /// <summary>
        /// Updates the bullet in the game.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            Rectangle collision;
            collision = Bounds;
            collision.X += (int)(Math.Cos(angle) * velocity);
            collision.Y += (int)(Math.Sin(angle) * velocity);

            foreach (EnemyActor e in Game1.map.enemies)
            {
                if (collision.Intersects(e.Bounds))
                {
                    e.damage(damage);                    
                    Game1.map.bulletsToRemove.Add(this);
                    Count--;
                    return;
                }
            }

            switch (CollisionDetection(collision))
            {
                case _CollisionType.noCollision:
                    X += (int)(Math.Cos(angle) * velocity);
                    Y += (int)-(Math.Sin(angle) * velocity);
                    break;
                default:
                    Game1.map.bulletsToRemove.Add(this);
                    Count--;
                    break;
            }
        }
        
        #endregion

        #region constructors
        /// <summary>
        /// Creates a PlayerBullet object with specified texture, on specified position,
        /// and with a specified velocity and angle.
        /// </summary>
        /// <param name="texture">The bullets texture</param>
        /// <param name="x">The bullets x-position</param>
        /// <param name="y">The bullets y-position</param>
        /// <param name="damage">A bullets inflicted damage value</param>
        /// <param name="velocity">The bullets velocity</param>
        /// <param name="angle">The bullets traversed angle</param>
        public PlayerBulletActor(Texture2D texture, int x = 0, int y = 0, int damage = 0, int velocity = 0, double angle = 0)
            : base(texture, x, y, damage, velocity, angle)
        {
            Count++;
        }

        #endregion
    }
}
